/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package pl.lodz.p.ftims.ProjektZespolowy2.facades;

import pl.lodz.p.ftims.ProjektZespolowy2.entities.User;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Łukasz Gadomski
 */
@Stateless
public class UsersFacade extends AbstractFacade<User> implements UsersFacadeLocal {
    @PersistenceContext(unitName = "primary")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public UsersFacade() {
        super(User.class);
    }
    
    @Override
    public User findByPesel(Integer pesel) {
        Query q = em.createNamedQuery("User.findByPesel");
        q.setParameter("pesel", pesel);
        User user = (User) q.getSingleResult();
        em.refresh(user);
        return user;
    }
    
}
